/**
 * 负责人管理
 * @author rxliuli
 */
const validate = (() => {
    const {limitLen} = RxElemValidator
    return RxFormValidator.generate([
        limitLen('name', '[负责人姓名] 长度最大为 20 位', 20),
        limitLen('idNumber', '[证件号码] 长度最大为 32 位', 32),
        limitLen('mobile', '[手机号码] 长度最大为 32 位', 32),
    ])
})()
const app = new BasicTableVue({
    data() {
        return {
            api: baseHouseOfficerApi,
            columns: [
                new TableColumn({width: 30, type: 'selection'}),
                new TableColumn({prop: 'id', title: 'ID'}),
                new TableColumn({prop: 'name', title: '负责人姓名'}),
                new TableColumn({
                    prop: 'idType',
                    title: '证件类型',
                    formatter: fieldFormatter.facade(fieldFormatter.baseCustomer.idTypeMap)
                }),
                new TableColumn({prop: 'idNumber', title: '证件号码'}),
                new TableColumn({prop: 'mobile', title: '移动电话'}),
                new TableColumn({prop: 'email', title: '邮箱'}),
                new TableColumn({prop: 'updateTime', title: '更新时间', formatter: TableColumn.datetimeFormat}),
                new TableColumn({prop: 'reportStatus', title: '报备状态', formatter: fieldFormatter.facade(fieldFormatter.baseData.reportStatusMap)}),
                new TableColumn({prop: 'operating', title: '操作', customComponent: true}),
            ],
            fileSelectorShow: false,
            validate,
        }
    },
    methods: {
        createForm() {
            return new BaseHouseOfficer()
        },
        update({row}) {
            forward('/basic-data/modify/admin_officer_modify.html', row)
        },
        async downloadTemplate() {
            await baseHouseOfficerApi.downloadTemplate('负责人信息管理导入模板.xlsx')
        },
        async insertReport(id) {
            if (await ajaxOption({
                res: this.api.insertReport(id),
                danger: '新增上报成功',
                success: '新增上报失败',
            })) {
                await this.searchPage()
            }
        },
        async updateReport(id) {
            if (await ajaxOption({
                res: this.api.updateReport(id),
                danger: '修改上报成功',
                success: '修改上报失败',
            })) {
                await this.searchPage()
            }
        },
    },
})
